#include <Agent.hpp>

Application::Agent::~Agent()
{}

Application::Agent::Agent()
{}

void Application::Agent::init()
{
    // iniciar la pantalla de inicio
    // iniciar las demas pantallas como la del juego en si, o la seleccionada

    /////////////////////////////////////
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	//Set OpenGL states
	//Enable zBuffering
	glEnable(GL_DEPTH_TEST);
	//Clear depth buffer.
	glClearDepth(1.0f);
	//Enable culling face
	glEnable(GL_CULL_FACE);
	glEnable(GL_NORMALIZE);
	//glEnable(GL_TEXTURE_2D);
	//glClearStencil(0);
	//Select the nicest correction possible.
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	//Set PolygonMode
	glPolygonMode(GL_FRONT, GL_FILL);
	//Enable lighting
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	///////////////////////////////////////////////////////////////
	float pos[] = {-3.0f, 15.0f, 5.0f};
	float amb[] = {0.0f ,0.0f, 0.0f};
	float dif[] = {1.0f, 1.0f, 1.0f};
	float spe[] = {1.0f, 1.0f, 1.0f};
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
	glLightfv(GL_LIGHT0, GL_POSITION, pos );
	glLightfv(GL_LIGHT0, GL_AMBIENT, amb );
	glLightfv(GL_LIGHT0, GL_DIFFUSE, dif );
	glLightfv(GL_LIGHT0, GL_SPECULAR, spe );
	//glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1f);
	//glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05f);
	//glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 30);
	//glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, LightDir);
	glEnable (GL_LIGHT0);
	/////////////////////////////////////

    Modeling::AppStream* stream = new Modeling::TextStream("../res/models/filer.SDF", "r");
	this->scene = new Drawing::Scene();
	stream->read(scene);
	scene->getAnimation()->play();
	delete stream;
}

void Application::Agent::display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// | GL_STENCIL_BUFFER_BIT);

    scene->animate();
}

void Application::Agent::reshape(int width, int height)
{
    // Reset The Current Viewport
	if (height == 0) height = 1;
	glViewport(0, 0, width, height);

	// Select The Projection Matrix
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.1f, 100.0f);

	// Select The Modelview Matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
